home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 20 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: news.rmii.com!usenet
  2. From: jcoffin@rmii.com (Jerry Coffin)
  3. Newsgroups: comp.std.c
  4. Subject: Re: static and extern, and a variable be both ?
  5. Date: Thu, 04 Jan 1996 17:33:43 GMT
  6. Organization: TAEUS
  7. Message-ID: <4cgv6u$ogu@natasha.rmii.com>
  8. References: <ahicksDKMG56.K20@netcom.com>
  9. NNTP-Posting-Host: slip8152.rmii.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. ahicks@netcom.com (Aaron Hicks at Netcom) wrote:
  13.  
  14. >   After much looking and little finding I have come to ask for your 
  15. >assistance.  I'm working on a project in which we believed the best way
  16. >to insure a 500K array was allocated corectly was to declare it as static  
  17. >and then when we needed to use it in a nother program to declare it there as 
  18. >an extern.  When we did this we got a variable undefined error during the
  19. >linking of the programs.  Now my question is this a standard C compiler 
  20. >thing or is this compiler wrong.  Below are the relative parts of the code:
  21.  
  22. [ ... ] 
  23.  
  24. >I have found that this will work if I just do not declare the array as 
  25. >a static in the first place.  It then will work fine, but we a slightly 
  26. >afraid that if we do not declare this as static when it is declared there
  27. >may not be enough memory left after the other parts of this program have 
  28. >ran of a while.
  29.  
  30. As long as the varaible is declared at file scope (i.e. outside any
  31. function), it'll have static storage duration (which seems to be what
  32. you want.)  If you use `static' explicitly, it will give the identifier
  33. internal linkage, which means it will only be visible within that
  34. translation unit. (i.e. that source module)
  35.  
  36. In short, it sounds like leaving the `static' off is exactly what you
  37. need, and shouldn't cause a problem.
  38.     Later,
  39.     Jerry.
  40.  
  41. /* I can barely express my own opinions; I certainly can't
  42.  * express anybody else's.
  43.  *
  44.  * The universe is a figment of its own imagination.
  45.  */
  46.  
  47.